home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -screenplay- / shareware / scott / source / source.lha / SCOTT.c < prev    next >
C/C++ Source or Header  |  1999-04-04  |  18KB  |  895 lines

  1. #include "SCOTT_A.c"
  2.  
  3. void choice(void)
  4. {
  5.     BYTE key;
  6.  
  7.     put_choice();
  8.     while (1) {
  9.         key = KeyInput();
  10.         //printf("Key: %c\n",key);
  11.         if (tolower(key) == 'e') {
  12.             close_all();
  13.             exit(0);
  14.         }
  15.         if (tolower(key) == 'r') {
  16.             cursor(FALSE);
  17.             WriteCON("Restore\n");
  18.             Speak("Restore");
  19.             OutReset();
  20.             if (RestoreGame() == FALSE) {
  21.                 Look();
  22.                 break;
  23.             }
  24.             else put_choice();
  25.         }
  26.         if ((tolower(key) == 's') && RESTART) {
  27.             cursor(FALSE);
  28.             WriteCON("Restart\n");
  29.             Speak("Restart");
  30.             OutReset();
  31.             if ((LoadRestart() == FALSE) && RESTART) {
  32.                 Restart();
  33.                 break;
  34.             }
  35.             else put_choice();
  36.         }
  37.     }
  38. }
  39.  
  40. void SaveBody(FILE *f)
  41. {
  42.     int ct;
  43.  
  44.     for(ct=0;ct<16;ct++)
  45.     {
  46.         fprintf(f,"%d %d\n",Counters[ct],RoomSaved[ct]);
  47.     }
  48.     fprintf(f,"%ld %d %hd %d %d %hd\n",BitFlags, (BitFlags&(1L<<DARKBIT))?1:0,
  49.         MyLoc,CurrentCounter,SavedRoom,GameHeader.LightTime);
  50.     for(ct=0;ct<=GameHeader.NumItems;ct++)
  51.         fprintf(f,"%hd\n",(short)Items[ct].Location);
  52.     fclose(f);
  53. }
  54.  
  55. void LoadBody(FILE *f)
  56. {
  57.     int ct;
  58.     short lo;
  59.     short DarkFlag;
  60.  
  61.     for(ct=0;ct<16;ct++)
  62.     {
  63.         fscanf(f,"%d %d\n",&Counters[ct],&RoomSaved[ct]);
  64.     }
  65.     fscanf(f,"%ld %d %hd %d %d %hd\n",
  66.         &BitFlags,&DarkFlag,&MyLoc,&CurrentCounter,&SavedRoom,
  67.         &GameHeader.LightTime);
  68.     /* Backward compatibility */
  69.     if(DarkFlag)
  70.         BitFlags|=(1L<<15);
  71.     for(ct=0;ct<=GameHeader.NumItems;ct++)
  72.     {
  73.         fscanf(f,"%hd\n",&lo);
  74.         Items[ct].Location=(unsigned char)lo;
  75.     }
  76.     fclose(f);
  77. }
  78.  
  79. BOOL SaveRestart()
  80. {
  81.     FILE *f;
  82.  
  83.     f = fopen(restart_file,"w");
  84.     if (f==NULL) return(TRUE);
  85.     SaveBody(f);
  86.     //SetProtection(restart_file,128);
  87.     restart_lock = Lock(restart_file,SHARED_LOCK);
  88.     return(FALSE);
  89. }
  90.  
  91. BOOL LoadRestart()
  92. {
  93.     FILE *f=
  94.  
  95.     f = fopen(restart_file,"r");
  96.     if (f==NULL) return(TRUE);
  97.     LoadBody(f);
  98.     return(FALSE);
  99. }
  100.  
  101. int PerformLine(int ct)
  102. {
  103.     int continuation=0;
  104.     int param[5],pptr=0;
  105.     int act[4];
  106.     int cc=0;
  107.  
  108.     while(cc<5)
  109.     {
  110.         int cv,dv;
  111.         cv=Actions[ct].Condition[cc];
  112.         dv=cv/20;
  113.         cv=cv%20;
  114.         //cv%=20;
  115.         switch(cv)
  116.         {
  117.             case 0:
  118.                 param[pptr++]=dv;
  119.                 break;
  120.             case 1:
  121.                 if(Items[dv].Location!=CARRIED)
  122.                     return(0);
  123.                 break;
  124.             case 2:
  125.                 if(Items[dv].Location!=MyLoc)
  126.                     return(0);
  127.                 break;
  128.             case 3:
  129.                 if(Items[dv].Location!=CARRIED&&
  130.                     Items[dv].Location!=MyLoc)
  131.                     return(0);
  132.                 break;
  133.             case 4:
  134.                 if(MyLoc!=dv)
  135.                     return(0);
  136.                 break;
  137.             case 5:
  138.                 if(Items[dv].Location==MyLoc)
  139.                     return(0);
  140.                 break;
  141.             case 6:
  142.                 if(Items[dv].Location==CARRIED)
  143.                     return(0);
  144.                 break;
  145.             case 7:
  146.                 if(MyLoc==dv)
  147.                     return(0);
  148.                 break;
  149.             case 8:
  150.                 if((BitFlags&(1L<<dv))==0)
  151.                     return(0);
  152.                 break;
  153.             case 9:
  154.                 if(BitFlags&(1L<<dv))
  155.                     return(0);
  156.                 break;
  157.             case 10:
  158.                 if(CountCarried()==0)
  159.                     return(0);
  160.                 break;
  161.             case 11:
  162.                 if(CountCarried())
  163.                     return(0);
  164.                 break;
  165.             case 12:
  166.                 if(Items[dv].Location==CARRIED||Items[dv].Location==MyLoc)
  167.                     return(0);
  168.                 break;
  169.             case 13:
  170.                 if(Items[dv].Location==0)
  171.                     return(0);
  172.                 break;
  173.             case 14:
  174.                 if(Items[dv].Location)
  175.                     return(0);
  176.                 break;
  177.             case 15:
  178.                 if(CurrentCounter>dv)
  179.                     return(0);
  180.                 break;
  181.             case 16:
  182.                 if(CurrentCounter<=dv)
  183.                     return(0);
  184.                 break;
  185.             case 17:
  186.                 if(Items[dv].Location!=Items[dv].InitialLoc)
  187.                     return(0);
  188.                 break;
  189.             case 18:
  190.                 if(Items[dv].Location==Items[dv].InitialLoc)
  191.                     return(0);
  192.                 break;
  193.             case 19: /* Only seen in Brian Howarth games so far */
  194.                 if(CurrentCounter!=dv)
  195.                     return(0);
  196.                 break;
  197.         }
  198.         cc++;
  199.     }
  200.     /* Actions */
  201.     act[0]=Actions[ct].Action[0];
  202.     act[2]=Actions[ct].Action[1];
  203.     act[1]=act[0]%150;
  204.     act[3]=act[2]%150;
  205.     act[0]/=150;
  206.     act[2]/=150;
  207.     cc=0;
  208.     pptr=0;
  209.     while(cc<4)
  210.     {
  211.         //printf("Action: %d\n",act[cc]);
  212.         if(act[cc]>=1 && act[cc]<52)
  213.         {
  214.             Output(Messages[act[cc]]);
  215.             Speak(Messages[act[cc]]);
  216.             Output("\n");
  217.         }
  218.         else if(act[cc]>101)
  219.         {
  220.             Output(Messages[act[cc]-50]);
  221.             Speak(Messages[act[cc]-50]);
  222.             Output("\n");
  223.         }
  224.         else switch(act[cc])
  225.         {
  226.             case 0: /* NOP */
  227.                 break;
  228.             case 52:
  229.                 if(CountCarried()==GameHeader.MaxCarry)
  230.                 {
  231.                     if(Options&YOUARE) {
  232.                         Output("You are carrying too much.\n");
  233.                         Speak("You are carrying too much.");
  234.                     }
  235.                     else {
  236.                         Output("I've too much to carry!\n");
  237.                         Speak("I've too much to carry!");
  238.                     }
  239.                     break;
  240.                 }
  241.                 if(Items[param[pptr]].Location==MyLoc)
  242.                     Redraw=1;
  243.                 Items[param[pptr++]].Location= CARRIED;
  244.                 break;
  245.             case 53:
  246.                 Redraw=1;
  247.                 Items[param[pptr++]].Location=MyLoc;
  248.                 break;
  249.             case 54:
  250.                 Redraw=1;
  251.                 MyLoc=param[pptr++];
  252.                 break;
  253.             case 55:
  254.                 if(Items[param[pptr]].Location==MyLoc)
  255.                     Redraw=1;
  256.                 Items[param[pptr++]].Location=0;
  257.                 break;
  258.             case 56:
  259.                 BitFlags|=1L<<DARKBIT;
  260.                 break;
  261.             case 57:
  262.                 BitFlags&=~(1L<<DARKBIT);
  263.                 break;
  264.             case 58:
  265.                 BitFlags|=(1L<<param[pptr++]);
  266.                 break;
  267.             case 59:
  268.                 if(Items[param[pptr]].Location==MyLoc)
  269.                     Redraw=1;
  270.                 Items[param[pptr++]].Location=0;
  271.                 break;
  272.             case 60:
  273.                 BitFlags&=~(1L<<param[pptr++]);
  274.                 break;
  275.             case 61:
  276.                 if(Options&YOUARE) {
  277.                     Output("You are dead.\n");
  278.                     Speak("You are dead.");
  279.                 }
  280.                 else {
  281.                     Output("I am dead.\n");
  282.                     Speak("I am dead.");
  283.                 }
  284.                 BitFlags&=~(1L<<DARKBIT);
  285.                 MyLoc=GameHeader.NumRooms; /* It seems to be what the code says! */
  286.                 Look();
  287.                 break;
  288.             case 62:
  289.             {
  290.                 /* Bug fix for some systems - before it could get parameters wrong */
  291.                 int i=param[pptr++];
  292.                 Items[i].Location=param[pptr++];
  293.                 Redraw=1;
  294.                 break;
  295.             }
  296.             case 63:
  297. doneit:         OutBuf("The game is now over!\n");
  298.                 Speak("The game is now over!");
  299.                 choice();
  300.                 break;
  301.             case 64:
  302.                 Look();
  303.                 break;
  304.             case 65:
  305.             {
  306.                 int ct=0;
  307.                 int n=0;
  308.                 while(ct<=GameHeader.NumItems)
  309.                 {
  310.                     if(Items[ct].Location==GameHeader.TreasureRoom &&
  311.                       *Items[ct].Text=='*')
  312.                         n++;
  313.                     ct++;
  314.                 }
  315.                 if(Options&YOUARE) {
  316.                     Output("You have stored ");
  317.                     Speak("You have stored ");
  318.                 }
  319.                 else {
  320.                     Output("I've stored ");
  321.                     Speak("I've stored ");
  322.                 }
  323.                 OutputNumber(n);
  324.                 SpeakNum(n);
  325.                 Output("treasures.\nOn a scale of 0 to 100, that scores ");
  326.                 Speak("treasures. On a scale of 0 to hundred that scores ");
  327.                 OutputNumber((n*100)/GameHeader.Treasures);
  328.                 SpeakNum((n*100)/GameHeader.Treasures);
  329.                 Output("points.\n");
  330.                 Speak("points.");
  331.                 if(n==GameHeader.Treasures)
  332.                 {
  333.                     Output("Well done.\n");
  334.                     Speak("Well done.");
  335.                     goto doneit;
  336.                 }
  337.                 break;
  338.             }
  339.             case 66:
  340.             {
  341.                 int ct=0;
  342.                 int f=0;
  343.                 if(Options&YOUARE) {
  344.                     Output("You are carrying:\n");
  345.                     Speak("You are carrying:");
  346.                 }
  347.                 else {
  348.                     Output("I'm carrying:\n");
  349.                     Speak("I'm carrying:");
  350.                 }
  351.                 while(ct<=GameHeader.NumItems)
  352.                 {
  353.                     if(Items[ct].Location==CARRIED)
  354.                     {
  355.                         if(f==1)
  356.                         {
  357.                             if (Options & TRS80_STYLE)
  358.                                 Output(". ");
  359.                             else
  360.                                 Output(" - ");
  361.                         }
  362.                         f=1;
  363.                         Output(Items[ct].Text);
  364.                         Speak(Items[ct].Text);
  365.                     }
  366.                     ct++;
  367.                 }
  368.                 if(f==0) {
  369.                     Output("Nothing");
  370.                     Speak("Nothing");
  371.                 }
  372.                 Output(".\n");
  373.                 break;
  374.             }
  375.             case 67:
  376.                 BitFlags|=(1L<<0);
  377.                 break;
  378.             case 68:
  379.                 BitFlags&=~(1L<<0);
  380.                 break;
  381.             case 69:
  382.                 GameHeader.LightTime=LightRefill;
  383.                 if(Items[LIGHT_SOURCE].Location==MyLoc)
  384.                     Redraw=1;
  385.                 Items[LIGHT_SOURCE].Location=CARRIED;
  386.                 BitFlags&=~(1L<<LIGHTOUTBIT);
  387.                 break;
  388.             case 70:
  389.                 clrscr(); /* pdd. */
  390.                 OutReset();
  391.                 break;
  392.             case 71:
  393.                 SaveGame();
  394.                 break;
  395.             case 72:
  396.             {
  397.                 int i1=param[pptr++];
  398.                 int i2=param[pptr++];
  399.                 int t=Items[i1].Location;
  400.                 if(t==MyLoc || Items[i2].Location==MyLoc)
  401.                     Redraw=1;
  402.                 Items[i1].Location=Items[i2].Location;
  403.                 Items[i2].Location=t;
  404.                 break;
  405.             }
  406.             case 73:
  407.                 continuation=1;
  408.                 break;
  409.             case 74:
  410.                 if(Items[param[pptr]].Location==MyLoc)
  411.                     Redraw=1;
  412.                 Items[param[pptr++]].Location= CARRIED;
  413.                 break;
  414.             case 75:
  415.             {
  416.                 int i1,i2;
  417.                 i1=param[pptr++];
  418.                 i2=param[pptr++];
  419.                 if(Items[i1].Location==MyLoc)
  420.                     Redraw=1;
  421.                 Items[i1].Location=Items[i2].Location;
  422.                 if(Items[i2].Location==MyLoc)
  423.                     Redraw=1;
  424.                 break;
  425.             }
  426.             case 76:    /* Looking at adventure .. */
  427.                 Look();
  428.                 break;
  429.             case 77:
  430.                 if(CurrentCounter>=0)
  431.                     CurrentCo